package leetcode_401_500;

public class LeeCode_415 {
    public static void main(String[] args) {
        System.out.println(addStrings("456", "777"));
    }
    private static String addStrings(String num1, String num2) {
        int l = num1.length() - 1, r = num2.length() - 1;
        StringBuilder ans = new StringBuilder();
        int more = 0;
        while (l >= 0 || r >= 0 || more > 0){
            int n1 = l >= 0 ? num1.charAt(l--) - '0' : 0;
            int n2 = r >= 0 ? num2.charAt(r--) - '0' : 0;
            int sum = n1 + n2 + more;
            more = sum / 10;
            ans.insert(0, sum % 10);
        }
        return ans.toString();
    }
}
